package com.ms3ds.mineInfo.api.factory;

import com.ms3ds.common.core.domain.R;
import com.ms3ds.mineInfo.api.RemoteTaskService;
import com.ms3ds.mineInfo.api.RemoteWorkerService;
import com.ms3ds.mineInfo.api.domain.Task;
import com.ms3ds.mineInfo.api.domain.Worker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 矿山信息服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteTaskFallbackFactory implements FallbackFactory<RemoteTaskService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteTaskFallbackFactory.class);

    @Override
    public RemoteTaskService create(Throwable throwable)
    {
        log.error("矿山信息服务调用失败:{}", throwable.getMessage());
        return new RemoteTaskService()
        {
            @Override
            public R<List<Task>> getTaskByTeamIdForRemote(Long teamId) {
                return R.fail("获取生产队id为" + teamId + "的开采任务信息失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> editTaskForRemote(Task task) {
                return R.fail("更新开采计划id为" + task.getId() + "的信息失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> generateMonthTask() {
                return R.fail("生成月度开采任务失败:" + throwable.getMessage());
            }

            @Override
            public R<Task> getYearTaskByTeamIdForRemote(Long teamId) {
                return R.fail("获取年度任务失败:" + throwable.getMessage());
            }

        };
    }
}
